package com.cgtong.android.mvp.presenter;

import com.cgtong.android.bean.SimpleResult;
import com.cgtong.android.http.callback.BaseCallBack;
import com.cgtong.android.mvp.contract.ReportProblemContract;
import com.cgtong.android.mvp.model.ReportProblemModel;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.subsciber.IProgressDialog;

import java.io.File;
import java.util.List;

import io.reactivex.disposables.Disposable;

/**
 * Created by chunc on 2017/10/23.
 */

public class ReportProblemPresenter implements ReportProblemContract.Presenter {
    private ReportProblemContract.Model mModle;
    private ReportProblemContract.View mView;

    public ReportProblemPresenter(ReportProblemContract.View mView) {
        this.mView = mView;
        mModle = new ReportProblemModel();
    }

    @Override
    public void onDestroy() {
        if (mView != null)
            mView = null;
    }

    @Override
    public Disposable httpCommitReport(long problemId, String desc, String address, double lng, double lat, int isDraft, int isOpen, List<File> imgFiles, File posFile, File voiceFile,int voiceTime, IProgressDialog progressDialog) {
        return mModle.httpCommitReport(problemId,desc, address, lng, lat, isDraft, isOpen, imgFiles, posFile, voiceFile,voiceTime, progressDialog, new BaseCallBack<SimpleResult>() {
            @Override
            public void onSuccess(SimpleResult simpleResult) {
                if(mView!=null){
                    mView.onHttpCommitReportSuccess(simpleResult);
                }
            }

            @Override
            public void onError(ApiException e) {
                if(mView!=null){
                    mView.onError(e);
                }
            }
        });
    }


}
